<template>
  <div v-if="identifyingInfo.id" style="padding: 6px">
    <el-tag v-if="identifyingInfo.extend.package_package_function_status">
      {{ $t('package-function.current') }}{{ title }}{{ $t('package-function.canAddUpTo') }}{{ identifyingInfo.extend.quantity }}{{ identifyingInfo.extend.unit }}{{ $t('package-function.Added') }}{{ identifyingInfo.identifying_count }}{{ identifyingInfo.extend.unit }}{{ $t('package-function.toIncreaseTheLimitPleaseUpgradeThePackage') }}
    </el-tag>
    <el-tag v-if="!identifyingInfo.extend.package_package_function_status">
      {{ $t('package-function.current') }}{{ title }}{{ $t('package-function.cannotSupportAdditionToActivatePleaseUpgradeThePackage') }}
    </el-tag>

    <el-tag
      v-if="getTimeDifference(identifyingInfo.current_package.sum_valid_time) <= (15 * 24 * 60 * 60) && getTimeDifference(identifyingInfo.current_package.sum_valid_time) > 0"
      type="danger"
    >
      {{ identifyingInfo.current_package.sum_valid_time }}【{{ $t('package-function.theCurrentPackageIsAboutToExpirePleaseRenewItInATimelyMannerAnd') }}{{ getTimeDayDifference(identifyingInfo.current_package.sum_valid_time) }}{{ $t('package-function.daysExpired') }}】
    </el-tag>
    <el-tag v-if="getTimeDifference(identifyingInfo.current_package.sum_valid_time) <= 0" type="danger">
      {{ identifyingInfo.current_package.sum_valid_time }}【{{ $t('package-function.theCurrentPackageHasExpiredPleaseRenewItInATimelyManner') }}】
    </el-tag>
  </div>
</template>

<script>
import { getIdentifyingInfo } from '@/api/package-function-backup'
export default {
  name: 'PackageFunctionText',
  props: ['title', 'identifying', 'token', 'isolate', 'isolateId'],
  data() {
    return {
      identifyingInfo: {
        id: undefined,
        extend: { quantity: 0 }
      }
    }
  },
  created() {
    this.onIdentifyingInfo()
  },
  methods: {
    onIdentifyingInfo() {
      if (!this.identifying) {
        return
      }
      const params = {}
      if (this.isolate === 'site') {
        params.site_id = this.isolateId
      }
      getIdentifyingInfo(this.identifying, params, this.token).then(res => {
        this.identifyingInfo = res
        this.$emit('emitPackageFunction', this.identifyingInfo)
      })
    },
    getTimeDifference(sumValidTime) {
      // sumValidTime = '2024-04-10 20:16:41'
      var timeSeconds = new Date(sumValidTime).getTime() / 1000 - parseInt(new Date().getTime() / 1000) // 相差秒
      var timeDay = (timeSeconds / 60 / 60 / 24) // 相差天数
      var timeHour = (timeSeconds / 60 / 60) // 相差小时
      var timeMinutes = (timeSeconds / 60) // 相差分钟

      console.log(timeDay, '相差天数')
      console.log(timeHour, '相差小时')
      console.log(timeMinutes, '相差分钟')
      console.log(timeSeconds, '相差秒')

      return timeSeconds
    },
    getTimeDayDifference(sumValidTime) {
      // sumValidTime = '2024-04-10 20:16:41'
      var timeSeconds = new Date(sumValidTime).getTime() / 1000 - parseInt(new Date().getTime() / 1000) // 相差秒
      var timeDay = (timeSeconds / 60 / 60 / 24)

      return parseFloat(timeDay.toFixed(2)) // 相差天数
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
